#include "ContinueBuilder.h"

#include "ScriptCompiler/ScriptFileContext.h"

#include "ScriptCompiler/AST/ContinueNode.h"

CContinueBuilder::CContinueBuilder(std::shared_ptr<CScriptFileContext> InContext)
{
    Context = InContext;
    Result = std::make_shared<CContinueNode>(InContext);

}

bool CContinueBuilder::ReadCurentToken()
{
    //read 'continue'
    {
        auto Token = Context->GetCurrentToken();
        if (Token->Type != EScriptTokenType::Continue)
        {
            Context->RaiseError(10027,Token, U"Expect 'continue' here");
            return false;
        }
        Result->Continue = Token;
        Context->CurrentTokenIndex++;
    }

    //check is current token is ';'
    auto Semicolon=Context->GetCurrentToken();
    if (Semicolon->Type == EScriptTokenType::Semicolon)
    {
        //skip ';'
        Context->CurrentTokenIndex++;
        return true;
    }
    else
    {
        Context->RaiseError(10028,Context->GetCurrentToken(), U"Expect ';' at end of continue-statement");
        return false;
    }


}
